package com.wiz.web.vo.criteria;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class ListCriteria<T> implements Serializable {
	private static final long serialVersionUID = -6242119301161625989L;
	
	private List<T> dataList;

	public List<T> getDataList() {
		return dataList;
	}

	public void setDataList(List<T> dataList) {
		this.dataList = dataList;
	}
	
	public static ListCriteria fromJson(String json, Class clazz) {
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
        Type objectType = type(ListCriteria.class, clazz);
        return gson.fromJson(json, objectType);
    }

    public String toJson(Class<T> clazz) {
    	Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
        Type objectType = type(ListCriteria.class, clazz);
        return gson.toJson(this, objectType);
    }
    
    static ParameterizedType type(final Class raw, final Type... args) {
        return new ParameterizedType() {
            public Type getRawType() {
                return raw;
            }

            public Type[] getActualTypeArguments() {
                return args;
            }

            public Type getOwnerType() {
                return null;
            }
        };
    }

	/*public static void main(String[] args) {
		Gson gson = new Gson();
		String sourceStr="{\"dataList\":[{\"hqId\":\"10031\",\"fpNo\":1,\"fpId\":\"998877\",\"stationId\":\"100311002\",\"stationName\":\"刘伟测试\",\"fuellingOrderId\":\"1003110020116030916309\",\"fpStartTime\":\"2016-03-09 16:01:18\",\"fpEndTime\":\"2016-03-09 16:01:30\",\"prId\":1,\"prName\":\"90#\",\"vol\":0.17,\"price\":2.0,\"totalVol\":377.87,\"totalAmount\":13775.53,\"memberId\":\"\",\"memberName\":\"\",\"memberLicencePlate\":null,\"groupNo\":\"201603041914\",\"stationAdminId\":\"1003110020001\",\"stationAdminName\":\"刘大爷\",\"stationCashier\":\"\",\"paidTypeId\":0,\"paidTypeName\":null,\"payStatus\":0,\"payTime\":\"0001-01-01 00:00:00\",\"receivableAmount\":0.34,\"realincomeAmount\":0.34,\"discountAmount\":0.0,\"intergalAmount\":0.0,\"authorityId\":\"C635931360744588464\",\"createdTime\":\"2016-03-09 16:01:31\"}]}";
		ListCriteria fuellingOrderCriteria = ListCriteria.fromJson(sourceStr, FuellingOrderCriteria.class);
		List<FuellingOrderCriteria> criteriaList = (List<FuellingOrderCriteria>) fuellingOrderCriteria.getDataList();
		System.out.println(criteriaList.size());
	}*/
}
